package main.Q2301_2400;

import java.util.HashSet;
import java.util.Set;

public class Q2331_2340 {
    public static void main(String[] args) {
        System.out.println("Question2331：计算布尔二叉树的值");
        System.out.println("Question2332：");
        System.out.println("Question2333：");
        System.out.println("Question2334：");
        System.out.println("Question2335：");
        System.out.println("Question2336：无限集中的最小数字");
        System.out.println("Question2337：");
        System.out.println("Question2338：");
        System.out.println("Question2339：");
        System.out.println("Question2340：");
    }
}

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() { }
    TreeNode(int val) {
        this.val = val;
    }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}

class Question2331 {
    public boolean process(TreeNode root) {
        if (root.left == null && root.right == null) {
            return root.val == 0 ? false : true;
        }
        boolean left = process(root.left);
        boolean right = process(root.right);
        if (root.val == 2) {
            return left || right;
        } else {
            return left && right;
        }
    }

    public boolean evaluateTree(TreeNode root) {
        return process(root);
    }
}

class Question2336 {
    int min;
    Set<Integer> set = null;

    public Question2336() {
        min = 1;
        set = new HashSet<>();
    }

    public int popSmallest() {
        set.add(min);
        int temp = min;
        min++;
        while (set.contains(min)) {
            min++;
        }
        return temp;
    }

    public void addBack(int num) {
        if (set.contains(num)) {
            set.remove(num);
            min = Math.min(num, min);
        }
    }
}